import { getToken } from '@/utils/auth'
export default {
  components: {},
  data() {
    return {
      uploadImgUrl: process.env.VUE_APP_BASE_API + 'trafficfly-manager/api/upload/uploadFile',
      uploadVideo: process.env.VUE_APP_BASE_API + '/v2/authorize/submitVideo.json',
      headers: {
        authorization: getToken()
      },
      fileList: [] // 上传的文件列表, 例如: [{name: 'food.jpg', url: 'https://xxx.cdn.com/xxx.jpg'}]
    }
  },
  computed: {
    // 上传服务器后返回的资源地址  在引用文件中监听此字段即可获得已上传的资源地址
    uploadedUrls() {
      const { fileList } = this
      console.log(this.fileList, 'filelist')
      if (!fileList.length) return []
      return fileList.map(v => {
        console.log(v, 'v')
        if (v.response) {
          return v.response.body
        } else {
          return v.url
        }
      })
    }
  },
  methods: {
    // 上传成功
    handleUploadSuccess(response, file, fileList) {
      console.log(response, file, fileList)
      this.fileList = fileList
      console.log(this.fileList, 789)
    },
    // 删除
    handleRemove(file, fileList) {
      console.log(file, fileList)
      this.fileList = fileList
      console.log(this.fileList,88999)
    },
    // 超出数量
    handleExceed(files, fileList) {
      const { limit = 1 } = this
      this.$message.warning(`当前限制选择${limit}个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
    },
    // 上传失败
    handleUploadError() {
      this.$message.error('上传失败')
    },
    // 删除前确认
    beforeRemove(file, fileList) {
      if (file && file.status === 'success') {
        return this.$confirm(`确定移除该图片？`)
      }
    },
    // 清空
    handleClear() {
      this.fileList = []
    }
  }
}
